<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>产品列表页</title>
    <link rel="icon" href="assets/img/favicon.ico">
    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-list.css"/>
    <link rel="stylesheet" type="text/css"
          href="css/widget-cartPanelView.css"/>
    <script src="js/vue.js" type="application/javascript"></script>
    <script src="js/axios.js" type="application/javascript"></script>
    <script src="js/base.js" type="application/javascript"></script>
    <style>
        .price_active {
            background-color: #1ad6fb;
        }
    </style>
</head>
<body>
<div id="app">
    <!--页面顶部-->
    <div id="nav-bottom">
        <!--顶部-->
        <div class="nav-top">
            <div class="top">
                <div class="py-container">
                    <div class="shortcut">
                        <ul class="fl">
                            <li class="f-item">爱思乐欢迎您！</li>
                            <li class="f-item">请 <a href="login.html" target="_blank">登录</a>
                                <span><a href="register.html" target="_blank">免费注册</a></span></li>
                        </ul>
                        <ul class="fr">
                            <li class="f-item">我的订单</li>
                            <li class="f-item space"></li>
                            <li class="f-item"><a href="home.html" target="_blank">我的爱思乐</a>
                            </li>
                            <li class="f-item space"></li>
                            <li class="f-item">爱思乐会员</li>
                            <li class="f-item space"></li>
                            <li class="f-item">企业采购</li>
                            <li class="f-item space"></li>
                            <li class="f-item">关注爱思乐</li>
                            <li class="f-item space"></li>
                            <li class="f-item" id="service"><span>客户服务</span>
                                <ul class="service">
                                    <li><a href="cooperation.html" target="_blank">合作招商</a></li>
                                    <li><a href="shoplogin.html" target="_blank">商家后台</a></li>
                                    <li><a href="cooperation.html" target="_blank">合作招商</a></li>
                                    <li><a href="#">商家后台</a></li>
                                </ul>
                            </li>
                            <li class="f-item space"></li>
                            <li class="f-item">网站导航</li>
                        </ul>
                    </div>
                </div>
            </div>
            <!--头部-->
            <div class="header">
                <div class="py-container">
                    <div class="yui3-g Logo">
                        <div class="yui3-u Left logoArea">
                            <a class="logo-bd" title="爱思乐" href="JD-index.html"
                               target="_blank"></a>
                        </div>
                        <div class="yui3-u Center searchArea">
                            <div class="search">
                                <form action="" class="sui-form form-inline">
                                    <!--searchAutoComplete-->
                                    <div class="input-append">
                                        <input type="text" id="autocomplete" type="text"
                                               class="input-error input-xxlarge" v-model="searchMap.keyword"/>
                                        <button class="sui-btn btn-xlarge btn-danger"
                                                @click="searchMap.pageNum=1;searchByKey()" type="button">搜索
                                        </button>
                                    </div>
                                </form>
                            </div>
                            <div class="hotwords">
                                <ul>
                                    <li class="f-item">爱思乐首发</li>
                                    <li class="f-item">亿元优惠</li>
                                    <li class="f-item">9.9元团购</li>
                                    <li class="f-item">每满99减30</li>
                                    <li class="f-item">亿元优惠</li>
                                    <li class="f-item">9.9元团购</li>
                                    <li class="f-item">办公用品</li>
                                </ul>
                            </div>
                        </div>
                        <div class="yui3-u Right shopArea">
                            <div class="fr shopcar">
                                <div class="show-shopcar" id="shopcar">
                                    <span class="car"></span> <a
                                        class="sui-btn btn-default btn-xlarge" href="javascript:alert('暂未实现')"
                                        target="_blank"> <span>我的购物车</span> <i class="shopnum">0</i>
                                </a>
                                    <div class="clearfix shopcarlist" id="shopcarlist"
                                         style="display: none">
                                        <p>"啊哦，你的购物车还没有商品哦！"</p>
                                        <p>"啊哦，你的购物车还没有商品哦！"</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="yui3-g NavList">
                        <div class="yui3-u Left all-sort">
                            <h4>全部商品分类</h4>
                        </div>
                        <div class="yui3-u Center navArea">
                            <ul class="nav">
                                <li class="f-item">服装城</li>
                                <li class="f-item">美妆馆</li>
                                <li class="f-item">团购</li>
                                <li class="f-item">有趣</li>
                                <li class="f-item">秒杀</a></li>
                            </ul>
                        </div>
                        <div class="yui3-u Right"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--list-content-->
    <div class="main">
        <div class="py-container">
            <!--selector-->
            <div class="clearfix selector">
                <div class="type-wrap">
                    <div class="fl key">商品分类</div>
                    <div class="fl value">
                        <a href="#" :class="{price_active:categoryFlag==index}" v-for="(category,index) in categoryList"
                           @click="addCondition('category',category,index);">{{category}}</a>
                    </div>
                    <div class="fl ext"></div>
                </div>
                <div class="type-wrap logo">
                    <div class="fl key brand">品牌</div>
                    <div class="value logos">
                        <ul class="logo-list">
                            <li :class="{price_active:brandFlag==index}" v-for="(brand,index) in brandList"
                                @click="addCondition('brand',brand,index);">{{brand}}
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="type-wrap">
                    <div class="fl key">价格</div>
                    <div class="fl value">
                        <ul class="type-list">
                            <li :class="{price_active:priceFlag==1}"><a
                                    @click="addCondition('price','0-500',1);">0-500元</a></li>
                            <li :class="{price_active:priceFlag==2}"><a @click="addCondition('price','500-1000',2);">500-1000元</a>
                            </li>
                            <li :class="{price_active:priceFlag==3}"><a @click="addCondition('price','1000-1500',3);">1000-1500元</a>
                            </li>
                            <li :class="{price_active:priceFlag==4}"><a @click="addCondition('price','1500-2000',4);">1500-2000元</a>
                            </li>
                            <li :class="{price_active:priceFlag==5}"><a @click="addCondition('price','2000-3000',5);">2000-3000元 </a>
                            </li>
                            <li :class="{price_active:priceFlag==6}"><a
                                    @click="addCondition('price','3000',6);">3000元以上</a></li>
                        </ul>
                    </div>
                    <div class="fl ext"></div>
                </div>
            </div>
            <!--details-->
            <div class="details">
                <div class="sui-navbar">
                    <div class="navbar-inner filter">
                        <ul class="sui-nav">
                            <li :class="{'active':sortFlag==1}" @click="sortSearch('',1,order=!order)"><a>综合</a></li>
                            <li><a>销量</a></li>
                            <li><a>新品</a></li>
                            <li><a>评价</a></li>
                            <li :class="{'active':sortFlag==4}" @click="sortSearch('price',4,order=!order)"><a>价格</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="goods-list">
                    <ul class="yui3-g">
                        <li class="yui3-u-1-5" v-for="good in goodsList">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <a :href="'item.html?goodId='+good.id" target="_blank"><img
                                            :src="good.image"/></a>
                                </div>
                                <div class="price">
                                    <strong> <em>¥</em> <i>{{good.price}}</i>
                                    </strong>
                                </div>
                                <div class="attr">
                                    <em v-html="good.name"></em>
                                </div>
                                <div class="cu">
                                    <em></em>
                                </div>
                                <div class="commit">
                                    <i class="command">已有{{good.commentNum}}人评价</i>
                                </div>
                                <div class="operate">
                                    <a :href="'getOrderInfo.html?goodId='+good.id" target="_blank"
                                       class="sui-btn btn-bordered btn-danger">购买</a>
                                    <a href="javascript:alert('暂未实现')" target="_blank" class="sui-btn btn-bordered btn-danger">购物车</a>
                                    <a class="sui-btn btn-bordered btn-danger">对比</a>
                                    <a class="sui-btn btn-bordered btn-danger">关注</a>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="fr page">
                    <div class="sui-pagination pagination-large">
                        <ul>
                            <!--								<li class="active"><a href="#">1</a></li>-->
                            <li v-for="i in pageNos"><a href="#" @click="queryForPage(i)">{{i}}</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <!--hotsale-->
            <div class="clearfix hot-sale">
                <h4 class="title">热卖商品</h4>
                <div class="hot-list">
                    <ul class="yui3-g">
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_01.png"/>
                                </div>
                                <div class="attr">
                                    <em>Apple苹果iPhone 6s (A1699)</em>
                                </div>
                                <div class="price">
                                    <strong> <em>¥</em> <i>4088.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有700人评价</i>
                                </div>
                            </div>
                        </li>
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_03.png"/>
                                </div>
                                <div class="attr">
                                    <em>金属A面，360°翻转，APP下单省300！</em>
                                </div>
                                <div class="price">
                                    <strong> <em>¥</em> <i>4088.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有700人评价</i>
                                </div>
                            </div>
                        </li>
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_04.png"/>
                                </div>
                                <div class="attr">
                                    <em>256SSD商务大咖，完爆职场，APP下单立减200</em>
                                </div>
                                <div class="price">
                                    <strong> <em>¥</em> <i>4068.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有20人评价</i>
                                </div>
                            </div>
                        </li>
                        <li class="yui3-u-1-4">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <img src="img/like_02.png"/>
                                </div>
                                <div class="attr">
                                    <em>Apple苹果iPhone 6s (A1699)</em>
                                </div>
                                <div class="price">
                                    <strong> <em>¥</em> <i>4088.00</i>
                                    </strong>
                                </div>
                                <div class="commit">
                                    <i class="command">已有700人评价</i>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            brandList: [],
            categoryList: [],
            goodsList: [],
            sortFlag: 1, // 控制排序样式
            priceFlag: 0, // 控制价格样式
            categoryFlag: -1,
            brandFlag: -1,
            order: true,
            searchMap: {
                keyword: '',
                pageNum: 1,
                pageSize: 10,
                sortField: '',
                sortRule: 'ASC',
                brand: '',
                category: '',
                price: ''
            },
            page: {},
            pageNos: []
        },
        methods: {
            searchByKey(){
                this.sortFlag= 1 // 控制排序样式
                this.priceFlag= 0 // 控制价格样式
                this.categoryFlag= -1
                this.brandFlag= -1
                this.searchMap.brand = '';
                this.searchMap.category = '';
                this.searchMap.price = '';
                this.search()
            },
            //搜索
            search: function () {
                console.log(JSON.stringify(this.searchMap));
                axios.post(urls.search_goods, this.searchMap).then(res => {
                    this.goodsList = res.data.goodList;
                    this.brandList = res.data.brandList;
                    this.categoryList = res.data.categoryList;
                    this.page = res.data.pages;
                    this.pageNos = [];
                    for (let i = 1; i <= this.page; i++) {
                        this.pageNos.push(i);
                    }
                })
            },
            //增加条件,搜索
            addCondition: function (key, value, index) {
                this.searchMap[key] = value;
                this.searchMap.pageNum = 1;
                if (key == "brand") {
                    this.brandFlag = index
                } else if (key == "category") {
                    this.categoryFlag = index
                } else if (key == "price") {
                    this.priceFlag = index
                }
                this.search();
            },
            //移除条件,搜索
            removeCondition: function (key) {
                delete this.searchMap[key];
                this.search();
            },
            //排序搜索
            sortSearch: function (sortField, sortFlag, isAsc) {
                this.searchMap.sortField = sortField;
                this.searchMap.sortRule = isAsc ? "ASC" : "DESC";
                this.sortFlag = sortFlag;
                this.search();
            },
            //点击页码查询
            queryForPage: function (pageNum) {
                if (pageNum < 1) {
                    return;
                }
                this.searchMap.pageNum = pageNum;
                this.search();//查询
            }
        },
        //页面加载时,执行查询
        created: function () {
            this.search();
        }
    })
</script>
</html>